package com.smec.remes.module.submit.adapter;

import android.content.Context;
import android.databinding.DataBindingUtil;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.smec.moblie.BR;
import com.smec.moblie.R;
import com.smec.moblie.databinding.LayoutRecyclerviewOtherBinding;
import com.smec.moblie.databinding.LayoutRecyclerviewOtherNewBinding;
import com.smec.moblie.location.Common;
import com.smec.remes.base.SmecBaseRecyclerViewHolder;
import com.smec.remes.bean.SubmitConfirmeChildren;
import com.smec.remes.bean.SubmitDetails;
import com.smec.remes.bean.SubmitDetailsConfirme;
import com.smec.remes.util.CommonUtils;

import java.util.ArrayList;

/**
 * Created by Administrator on 2017/12/20.
 */

public class SmecShouChildrenAdapter extends RecyclerView.Adapter<SmecBaseRecyclerViewHolder>{

    private Context mcontext;
    private ArrayList<String> timeList=new ArrayList<>();
    private ArrayList<SubmitDetailsConfirme> submitDetailsConfirmeArrayList=new ArrayList<>();
    public void setArrayList( ArrayList<SubmitDetailsConfirme> list){
        submitDetailsConfirmeArrayList=list;
        notifyDataSetChanged();
    }

    public SmecShouChildrenAdapter(Context context) {
        this.mcontext=context;
    }


    @Override
    public SmecBaseRecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        LayoutRecyclerviewOtherNewBinding layoutRecyclerviewOtherNewBinding=DataBindingUtil.inflate
                (LayoutInflater.from(parent.getContext()), R.layout.layout_recyclerview_other_new,parent,false);
        layoutRecyclerviewOtherNewBinding.ivQuanxuan.setVisibility(View.GONE);
        SmecBaseRecyclerViewHolder smecBaseRecyclerViewHolder=new
                SmecBaseRecyclerViewHolder(layoutRecyclerviewOtherNewBinding.getRoot());
        smecBaseRecyclerViewHolder.setViewType(viewType);
        smecBaseRecyclerViewHolder.setBinding(layoutRecyclerviewOtherNewBinding);
        return smecBaseRecyclerViewHolder;
    }

    @Override
    public void onBindViewHolder(SmecBaseRecyclerViewHolder holder, int position) {
        LayoutRecyclerviewOtherNewBinding layoutRecyclerviewOtherNewBinding= (LayoutRecyclerviewOtherNewBinding) holder.getBinding();
        layoutRecyclerviewOtherNewBinding.setVariable(BR.meihuo,submitDetailsConfirmeArrayList.get(position));
        if("CANCELED".equals(submitDetailsConfirmeArrayList.get(position).getBackStatus())){
            layoutRecyclerviewOtherNewBinding.tvRetun.setVisibility(View.VISIBLE);
            layoutRecyclerviewOtherNewBinding.llWeishouhuo.setBackground(
                    mcontext.getResources().getDrawable(R.drawable.search_stokre_yellow));
        }
//        layoutRecyclerviewOtherNewBinding.tvTime.setText(submitDetailsConfirmeArrayList.get(position).getReceiptDate());
        checkTime(position,layoutRecyclerviewOtherNewBinding);
    }

    /**
     * 检查时间
     * @param position
     * @param layoutRecyclerviewOtherNewBinding
     */
    private void checkTime(int position,LayoutRecyclerviewOtherNewBinding layoutRecyclerviewOtherNewBinding){
        if(submitDetailsConfirmeArrayList.get(position).getFlag()!=null  && submitDetailsConfirmeArrayList.get(position).getFlag().equals("F")){
            layoutRecyclerviewOtherNewBinding.llShouhuoTime.setVisibility(View.VISIBLE);
        }else {
            layoutRecyclerviewOtherNewBinding.llShouhuoTime.setVisibility(View.GONE);
        }
    }

    @Override
    public int getItemCount() {
        return submitDetailsConfirmeArrayList.size();
    }
}
